package com.erpanderp.wam.asset.view;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;

import com.erpanderp.wam.asset.model.entity.AssetRequest;
import com.erpanderp.wam.asset.model.service.AssetRequestDAO;
import com.erpanderp.wam.usm.model.entity.user.WAMUser;
import com.erpanderp.wam.util.CommonLookup;

@ManagedBean
@ViewScoped
public class AdminAssignAssetsBean implements Serializable{


	private static final long serialVersionUID = 1L;
	HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
	ServletContext context = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
	private WAMUser wamUser = (WAMUser) session.getAttribute(CommonLookup.SESSION_ATTRIBUTE_WAMUSER);
	private TimeZone timeZone = TimeZone.getDefault();
	
	 private List<AssetRequest> assetRequestList = new ArrayList<AssetRequest>();
	 private List<String> modulesList = new ArrayList<String>();
	 
	 private AssetRequestDAO assetRequestDAO =new AssetRequestDAO();

	public AdminAssignAssetsBean() {
		assetRequestList = assetRequestDAO.getAssetRequestsBySysAdminId(wamUser.getEmployee().getEmployeeId());
	}
	
	public String assignAssetAction() {		 
	 try{			
		  Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
		  String assetCode = params.get("assetCode");
		  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("assetCode", assetCode);
		  FacesContext.getCurrentInstance().getExternalContext().redirect("/wam/asset/assignassets.html?assetCode="+assetCode);
		
		}catch(Exception e){
    	   e.printStackTrace();
	    }
	 	return "printassetrequest";	 
	}
	
	//GENERATE SETTERS AND GETTERS
	public HttpSession getSession() {
		return session;
	}

	public void setSession(HttpSession session) {
		this.session = session;
	}

	public ServletContext getContext() {
		return context;
	}

	public void setContext(ServletContext context) {
		this.context = context;
	}

	public WAMUser getWamUser() {
		return wamUser;
	}

	public void setWamUser(WAMUser wamUser) {
		this.wamUser = wamUser;
	}

	public List<AssetRequest> getAssetRequestList() {
		return assetRequestList;
	}

	public void setAssetRequestList(List<AssetRequest> assetRequestList) {
		this.assetRequestList = assetRequestList;
	}

	public List<String> getModulesList() {
		return modulesList;
	}

	public void setModulesList(List<String> modulesList) {
		this.modulesList = modulesList;
	}

	public AssetRequestDAO getAssetRequestDAO() {
		return assetRequestDAO;
	}

	public void setAssetRequestDAO(AssetRequestDAO assetRequestDAO) {
		this.assetRequestDAO = assetRequestDAO;
	}


	public TimeZone getTimeZone() {
		return timeZone;
	}


	public void setTimeZone(TimeZone timeZone) {
		this.timeZone = timeZone;
	}

	
}
